package com.fengmi.mapper;

import com.fengmi.entity.SysRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author 123
 * @Date 2022/2/10 11:22
 * @Version 1.0
 */


public interface SysRoleMapper {
    //条件及分页查询角色信息
    List<SysRole> findRolesByWhere(SysRole sysRole);

    //修改角色的启用状态
    @Update("update sys_role set enable = #{enable} where role_code = #{roleCode}")
    public int updateEnable(String roleCode,Integer enable);

    // 保存添加角色
    @Insert("INSERT INTO sys_role  (role_code,role_name,role_desc,role_type,create_time,enable) " +
            "VALUES (#{roleCode},#{roleName},#{roleDesc},#{roleType},#{createTime},#{enable})")
    public int saveAddRole(SysRole sysRole);

    //查询所有角色信息
    @Select("select * from sys_role")
    public List<SysRole> findAll();

    //修改角色信息
    public int updateRoleBasicInfo(SysRole sysRole);

    //保存分配权限,批量添加
    public int saveRolePermissions(String roleCode,String[] permissionIds);

    //删除角色对应的所有权限
    @Delete("delete from sys_role_permission where role_id =#{roleCode}")
    public int deleteAllPermissionsByRoleId(String roleCode);

    //查询角色对应的权限信息
    @Select("select perm_id from sys_role_permission where role_id = #{roleId}")
    public List<String> findAllPermissionsByRoleId(String roleId);
}
